import numpy as np

with open ('INDEX_20210127.txt')as f:
    data = f.readlines()
    data_str = ''
    # print(data)  # ['ZCTH,20210127,90,90,80,80,0\n', 'ZCTW,20210127,20,20,10,10,0\n', ...]
    # !!! Request：[['ZCTH,20210127,90,90,80,80,0'], ['ZCTW,20210127,20,20,10,10,0\n'], ...] 
    for i in data:
        data_str = data_str + i
        # print('zcth,202031233, 09, 8, 8\n' + 'fwjo,fw ,ewf,qfe,fewfe\n')
    # data_str.split(',')
    # print(data_str)
    # ZBTW,20210127,20,20,10,10,0
    # ZCFD,20210127,10,20,0.01,10,0
    # ZCFI,20210127,30,50,30,30,0
    data01 = data_str.split('\n')
    # print(data01)  # ['addrA,20210127,-152,-102,-165,-143,0', 'addrC,20210127,-75,-75,-242,-220,0']
    list01 = ['a', 'b', 'c', 'd']
    list02 = np.array(list01).reshape(1,4)
    # print(list02)

a = [   ['SSCM',20210127,13159.02,13159.02,12753.9,12812.68,0],
        ['SSDI',20210127,4.65,4.65,4.65,4.65,0],
        ['SSEW',20210127,378.85,380.42,374.51,377.08,0],
        ['SVTR',20210127,186.42,186.44,178.59,180.4,0],
        ['TTMT',20210127,310.64,310.79,301.98,302.59,65161700]
    ]

# for循环
dict01 = {}
for x in a:
    dict01[x[0]] = x[3]
print(dict01)

# 表达式
dict02 = {x[0]:x[3] for x in a}
print(dict02)

names = ['张三', '李四', '王五', '赵六', '李四', '张三', '赵六', '赵六', '王五', '赵六', '刘德华']
# names.count('张三')

# for循环
dict03 = {}
for k in names:
    dict03[k] = names.count(k)
print(dict03)

# 字典生成式
dict04 = {k:names.count(k) for k in names}
# 加个条件:
dict05 = {k:names.count(k) for k in names if names.count(k) > 1}
print(dict05)

# 两个一维列表生成字典
addr_En = ['CHA', "ENG", 'GER']
addr_En2 = [['CHA'], ["ENG"], ['GER']]
print(f'{addr_En[1], addr_En2[1]}')  # 取出来一个是字符串，一个仍然是列表
addr_Cn = ['中国', '英国', '德国']
# list_CN_EN = zip(addr_Cn, addr_En)
# # for i in list_CN_EN:
# #     print(i)
dict06 = {k[0]:k[1] for k in zip(addr_Cn, addr_En)}
print(dict06)